package com.jiuli.liping.util;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//public class CrosFilter implements Filter {
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        HttpServletResponse res = (HttpServletResponse) response;
//        //*号表示对所有请求都允许跨域访问
//        res.addHeader("Access-Control-Allow-Origin", "*");
//        res.addHeader("Access-Control-Allow-Methods", "*");
//        chain.doFilter(request, response);
//    }
//}

@Component
@WebFilter(filterName = "CrosFilter", urlPatterns = "/*")
public class CrosFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        //*号表示对所有请求都允许跨域访问
        //res.addHeader("Access-Control-Allow-Origin", "*");
        //res.addHeader("Access-Control-Allow-Methods", "*");
        chain.doFilter(request, response);
    }
}
